package function;

import java.util.Random;

public class 交换数组 {
    public static void main(String[] args) {
        int arr[] = { 1, 2, 3, 4, 5 };
        Random r = new Random();

        for (int i = 0; i < arr.length; i++) {
            int number = r.nextInt(arr.length);
            swap(arr, i, number);
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }

    public static void swap(int arr[], int a, int b) {
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }

}
